package kordegi.forumsystem.common.lang;

import lombok.Data;

/**
 * @author kordegi
 * @date 2022.05.01 16:50
 * @Description 统一返回结果封装
 */

@Data
public class Result {
    private String code;

    private String message;

    private Object data;

    public static Result succ(Object data){
        Result r = new Result();
        r.setCode("200");
        r.setData(data);
        r.setMessage("Done successfully");
        return r;
    }

    public static Result succ(String message, Object data){
        Result r = new Result();
        r.setCode("200");
        r.setData(data);
        r.setMessage(message);
        return r;
    }

    public static Result fail(String message){
        Result r = new Result();
        r.setCode("-1");
        r.setData(null);
        r.setMessage(message);
        return r;
    }

    public static Result fail(String message, Object data){
        Result r = new Result();
        r.setCode("-1");
        r.setData(data);
        r.setMessage(message);
        return r;
    }
}
